﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using VideoClassLibrary.Model;
using VideoClassLibrary.BusinessLogicLayer;
using System.IO;

public partial class CourseManagement_UpdateCourse :AdminUserBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            CourseModule cm = new CourseModule();
            int ID = Convert.ToInt32(Request.QueryString["CID"].ToString());
            V_course cour = cm.GetCourseModelById(ID);
            txtCourseName.Text = cour.VC_name;
            hidTrainClassIdList.Value = cour.TrainClassID.ToString();
            TextArea1.Text = cour.VC_desc;
            txtcontent.Text = cour.Vc_content;
            txttagerUser.Text = cour.Vc_targetUsers;
            txtTrainClassName.Text = cour.TrainClassName;
            TeacherModule ta = new TeacherModule();
            List<V_School> vs = new List<V_School>();
            vs = ta.GetSchool();
            dlschool.DataSource = vs;
            dlschool.DataBind();

            if (this.CurrentUser.SchoolID == 0)
            {
            }
            else
            {
                dlschool.SelectedValue = this.SchoolID.ToString();
                dlschool.Enabled = false;
                //摄像头控制，运营商能修改
               
            }
        }
    }
    protected void btnReg_Click(object sender, EventArgs e)
    {
        CourseModule cm = new CourseModule();
        V_course course = new V_course();
        course.ID = Convert.ToInt32(Request.QueryString["CID"].ToString());
        course.SchoolID = Convert.ToInt32(dlschool.SelectedValue);
        course.TrainClassID = Convert.ToInt32(hidTrainClassIdList.Value);
        course.Update_time = DateTime.Now;
        course.VC_desc = TextArea1.Text.ToString();
        course.VC_name = txtCourseName.Text.Trim();
        course.Vc_content = txtcontent.Text.ToString();
        course.Vc_targetUsers = txttagerUser.Text;

        string fileExtension = string.Empty;
        if (!string.IsNullOrEmpty(this.fuNewsImage.FileName))//修改图片
        {
            fileExtension = System.IO.Path.GetExtension(this.fuNewsImage.FileName);
            if (fileExtension != "" && fileExtension.ToLower() != ".jpg" && fileExtension.ToLower() != ".gif")
            {
                PageHelper.AlterMsg("图片格式只支持jpg/gif");
                return;
            }
            string dictionarySavedPath = PageHelper.GetWebConfigValue("SchoolImagePath");
            dictionarySavedPath += "\\Images\\SchoolId\\Course\\";
            dictionarySavedPath = dictionarySavedPath.Replace("SchoolId", this.SchoolID.ToString());
            if (!Directory.Exists(dictionarySavedPath))
            {
                Directory.CreateDirectory(dictionarySavedPath);
            }
            // dictionarySavedPath = Server.MapPath(PageHelper.ApplicationPath) + PageHelper.GetWebConfigValue("VideoPath").Replace("SchoolId", currentSchoolId.ToString());   
            //保存logo的文件夹绝对路径

            string logfileSavedPath = dictionarySavedPath +  course.ID.ToString() + fileExtension;
            //fileSavedPath = dictionarySavedPath + "/logo" + fileExtension;
            this.fuNewsImage.SaveAs(logfileSavedPath);

            course.CourseImage = ("/Images/SchoolId/Course/" + course.ID.ToString() + fileExtension).Replace("SchoolId", this.SchoolID.ToString());
        }

        cm.UpdateCourseModel(course);
        PageHelper.AlterMsgAndRedirect("修改课程成功！", "SearchCourseList.aspx");
    }
  
}
